package com.yuan.zsschool.ui;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yuan.base.framework.BaseFrameworkFragment;
import com.yuan.base.framework.BaseUserManager;
import com.yuan.base.framework.bean.UserInfo;
import com.yuan.base.framework.image.BaseImageLoad;
import com.yuan.zsschool.AppContext;
import com.yuan.zsschool.R;
import com.yuan.zsschool.ui.classManage.ClassManageActivity;
import com.yuan.zsschool.ui.me.ParentInfoActivity;
import com.yuan.zsschool.ui.me.SettingActivity;
import com.yuan.zsschool.ui.permission.MainAccountExamineActivity;
import com.yuan.zsschool.ui.permission.PermissionActivity;

/**
 * 我的
 */
public class MainMyFragment extends BaseFrameworkFragment {

	// --------------------------控件--------------------------
	private LinearLayout layoutInfo;
	private LinearLayout layout_class_manage;
	private LinearLayout ll_main_account;
	private TextView tv_user_name;
	private TextView tv_user_phone;
	private ImageView iv_user_avatar;
	// --------------------------变量--------------------------

	@Override
	protected int getLayoutId() {
		return R.layout.fragment_main_my;
	}

	@Override
	protected void bindViews() {
		layoutInfo = findViewById(R.id.layout_info);
		layout_class_manage = findViewById(R.id.layout_class_manage);
		ll_main_account = findViewById(R.id.ll_main_account);
		tv_user_name = findViewById(R.id.tv_user_name);
		tv_user_phone = findViewById(R.id.tv_user_phone);
		iv_user_avatar = findViewById(R.id.iv_user_avatar);
		layoutInfo.setOnClickListener(v -> startActivity(new Intent(context, ParentInfoActivity.class)));
		layout_class_manage.setOnClickListener(v -> startActivity(new Intent(context, ClassManageActivity.class)));

		setOnClickListener(R.id.ll_permission_manager, v -> startActivity(new Intent(context, PermissionActivity.class)));
		setOnClickListener(R.id.rl_setting, v -> startActivity(new Intent(context, SettingActivity.class)));
		setOnClickListener(R.id.ll_main_account, v -> startActivity(new Intent(context, MainAccountExamineActivity.class)));
	}

	@Override
	protected void initUI() {
		UserInfo user = BaseUserManager.getUser();
		tv_user_name.setText(user.getName());
		tv_user_phone.setText(user.getPhone1());
		BaseImageLoad.loadCircularAvatar(user.getSpic(), iv_user_avatar);
		if (AppContext.isMaster()) {
			layout_class_manage.setVisibility(View.VISIBLE);
			ll_main_account.setVisibility(View.GONE);
		} else {
			layout_class_manage.setVisibility(View.GONE);
			ll_main_account.setVisibility(View.VISIBLE);
		}
	}

	@Override
	public void onHiddenChanged(boolean hidden) {
		super.onHiddenChanged(hidden);
	}

	@Override
	public void onResume() {
		super.onResume();
		initUI();
	}


	@Override
	public void onStart() {
		super.onStart();
	}
}
